{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/maritalk.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
    "\n",
    "# Maritalk\n",
    "\n",
    "## Introduction\n",
    "\n",
    "MariTalk is an assistant developed by the Brazilian company [Maritaca AI](https://www.maritaca.ai).\n",
    "MariTalk is based on language models that have been specially trained to understand Portuguese well.\n",
    "\n",
    "This notebook demonstrates how to use MariTalk with llama-index through a simple example."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installation\n",
    "If you're opening this Notebook on colab, you will probably need to install LlamaIndex."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install llama-index\n",
    "!pip install llama-index-llms-maritalk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## API Key\n",
    "You will need an API key that can be obtained from chat.maritaca.ai (\"Chaves da API\" section)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Usage\n",
    "\n",
    "### Chat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core.llms import ChatMessage\n",
    "from llama_index.llms.maritalk import Maritalk\n",
    "\n",
    "# To customize your API key, do this\n",
    "# otherwise it will lookup MARITALK_API_KEY from your env variable\n",
    "# llm = Maritalk(api_key=\"<your_maritalk_api_key>\")\n",
    "\n",
    "llm = Maritalk()\n",
    "\n",
    "# Call chat with a list of messages\n",
    "messages = [\n",
    "    ChatMessage(\n",
    "        role=\"system\",\n",
    "        content=\"You are an assistant specialized in suggesting pet names. Given the animal, you must suggest 4 names.\",\n",
    "    ),\n",
    "    ChatMessage(role=\"user\", content=\"I have a dog.\"),\n",
    "]\n",
    "\n",
    "response = llm.chat(messages)\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Few-shot examples\n",
    "\n",
    "We recommend using the `llm.complete()` method when using the model with few-shot examples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"\"\"Classifique a resenha de filme como \"positiva\" ou \"negativa\".\n",
    "\n",
    "Resenha: Gostei muito do filme, é o melhor do ano!\n",
    "Classe: positiva\n",
    "\n",
    "Resenha: O filme deixa muito a desejar.\n",
    "Classe: negativa\n",
    "\n",
    "Resenha: Apesar de longo, valeu o ingresso..\n",
    "Classe:\"\"\"\n",
    "\n",
    "response = llm.complete(prompt, stopping_tokens=[\"\\n\"])\n",
    "print(response)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
